HardDelete a deleted object with hierarchy

Hello,

 

At least since DOORS 9.3, it is possible to purge a deleted object and its hierrarchy (Edit -> Object -> Purge...)

 

Is there a DXL function doing exactly the same?

 

Thanks in advance.

 

Best regards,

MattMar


MattMar - Tue Mar 22 09:52:37 EDT 2016

Re: HardDelete a deleted object with hierarchy
DOORSHAM - Tue Mar 22 12:02:13 EDT 2016

You might want to look in help file  at:

hardDelete (object)

Declaration

void hardDelete(Object o) 
void delete(Object o) 

Operation

Removes object o; the object cannot be recovered with undelete following this operation. If the operation fails, returns an error message (see also the canDelete function).

The form delete is provided for backwards compatibility only. The function hardDelete should be used for all new programs.

Re: HardDelete a deleted object with hierarchy
MattMar - Tue Mar 22 12:06:20 EDT 2016

Hello,

 

Thank you for your answer but hardDelete() does not work on deleted object and does not work on object with descendant whereas the function in the menu works in these cases.

 

The only solution I have is to implement my own function to hardDelete object with the hierrarchy.

 

Best regards,

MattMar

Re: HardDelete a deleted object with hierarchy
DOORSHAM - Tue Mar 22 13:35:59 EDT 2016

MattMar - Tue Mar 22 12:06:20 EDT 2016

Hello,

 

Thank you for your answer but hardDelete() does not work on deleted object and does not work on object with descendant whereas the function in the menu works in these cases.

 

The only solution I have is to implement my own function to hardDelete object with the hierrarchy.

 

Best regards,

MattMar

Look at:  string purgeObjects_(Module mod)
 

Re: HardDelete a deleted object with hierarchy
PekkaMakinen - Wed Mar 23 02:10:32 EDT 2016

Some earlier discussions on the same issue, with code examples

 

https://www.ibm.com/developerworks/community/forums/html/topic?id=b678b4eb-cd98-4c96-98be-d54e76cececa&ps=25

 

and

 

https://www.ibm.com/developerworks/community/forums/html/topic?id=996bd5cf-bd41-4d56-a504-a7b9457c6163&ps=25

Re: HardDelete a deleted object with hierarchy
MattMar - Wed Mar 23 05:03:45 EDT 2016

Hello,

 

Thanks to all for your replies.

 

What I need to do is to purge (not softDelete) all objects deleted 6 months ago or earlier which has been baselined since it has been deleted.

 

Whenever I get deleted object with hierarchy it is quite a mess as there many cases to manage (deleted objects with children and descendants, DOORS tables...).

 

The only solution I found is the following:

 

/*
 *      This function tries to hardDelete object o
 *      If it succeeds it returns true
 *
 */
bool myHardDelete(Object o) {
        bool bRes = false

        string sMsg
        noError()
        hardDelete(o)
        sMsg = lastError()
        if (null sMsg || sMsg == "") {
                bRes = true
                flushDeletions()
        }
        return bRes
}

/*
 *      This function retrieves all descendant of the object to purge
 *      If it succeeds it returns true
 *
 */
bool myPurgeObject(Object o) {
        bool bRes = false
        bool bFound = false
        
        // List of descendants to be deleted
        Skip skpList = create
        
        int nbObjects = 0

        Module m = module(o)

        current = m
        
        filtering off
        
        sorting(false)
        
        Object oTgt

        // hardDelete only works on undeleted objects. Undeleting object undelete descendants
        if (isDeleted(o)) undelete(o)

        // Retrieve all descendants of the object
        for oTgt in entire(m) do {
                if (!matches("^" number(o) "\\.", number(oTgt))) {
                        // No more descendants
                        if (bFound) break
                        
                        // We have reached the parent object
                        if (oTgt == o) bFound = true
                        
                        continue
                }
                
                // oTgt is a descendant of o and must be deleted
                put(skpList, nbObjects++, oTgt)
        }

        print "\n"

        nbPrev = nbObjects

        int iKey

        // While we have desendants we try to delete them
        while (nbObjects > 0) {
                for oTgt in skpList do {
                        iKey = (int key skpList)
                        if (myHardDelete(oTgt)) {
                                nbObjects--
                                delete(skpList, iKey)
                        }
                }
        
                // If number of descendants remains twice stop trying to purge descendants
                if (nbPrev == nbObjects) break

                nbPrev = nbObjects
        }

        delete(skpList)

        // Purge object o
        if (myHardDelete(o)) {
                // if all descendants have been deleted return true
                if (nbObjects == 0) bRes = true
        } else {
                // If purge fails softDelete object
                softDelete(o)
        }
        
        return bRes
}